package com.neusoft.tools;

import com.neusoft.nep.entity.nepsFeedback;

import java.time.LocalDate;

/**
 * 用于保持反馈状态
 */
public class FeedbackSession {
    private static FeedbackSession instance;
    private nepsFeedback feedback;
    private FeedbackSession() {
    }
    public static FeedbackSession getInstance() {
        if (instance == null) {
            synchronized (FeedbackSession.class) {
                if (instance == null) {
                    instance = new FeedbackSession();
                    instance.feedback = new nepsFeedback();
                }
            }
        }
        return instance;
    }

    public nepsFeedback getFeedback() {
        return feedback;
    }

    public void setUser(){
        feedback.setUsername(UserSession.getInstance().getLoggedInUser().getUserName());
        feedback.setPhoneNumber(UserSession.getInstance().getLoggedInUser().getPhoneNumber());
    }

    public void setLocation(String province, String city, String address){
        feedback.setProvince(province);
        feedback.setCity(city);
        feedback.setAddress(address);
    }

    public void setAQI(String AQI, String feedbackText){
        LocalDate today = LocalDate.now();
        feedback.setLevel(AQI);
        feedback.setContent(feedbackText);
        feedback.setDate(today.toString());
    }
}
